package edu.nf.ch04.service.impl;

import edu.nf.ch04.entity.Student;
import edu.nf.ch04.mapper.StudentMapper;
import edu.nf.ch04.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;


/**
 * @Author gjh
 * @Date 2025/9/27
 * @Description:
 */
@Service
@RequiredArgsConstructor
public class StudentServiceImpl implements StudentService {

    private final StudentMapper studentMapper;

    private final RedisTemplate<String, Object> redisTemplate;

    @Override
    public Student findStuName(Integer id) {
        if(!redisTemplate.hasKey("stu:"+id)){
            Student stu = studentMapper.getStudents(id);
            redisTemplate.opsForValue().set("stu:"+id,stu);
        }
        return (Student) redisTemplate.opsForValue().get("stu:"+id);
    }
}
